<?php
require_once(DP_BASE_DIR."/modules/projects/items/projectitems.class.php");
$obj = new CMdProject_items();
$msg = '';

if (!$obj->bind( $_POST )) {
    $AppUI->setMsg( $obj->getError(), UI_MSG_ERROR );
    $AppUI->redirect();
}

$del = dPgetParam( $_POST, 'del', 0 );

// prepare (and translate) the module name ready for the suffix
$AppUI->setMsg( '' );
if ($del) {
    if (($msg = $obj->delete())) {
        $AppUI->setMsg( $msg, UI_MSG_ERROR );
        $AppUI->redirect();
    } else {
        $AppUI->setMsg( "deleted", UI_MSG_ALERT, true );
        $AppUI->redirect( "m=projects" );
    }
} else {
    $isNotNew = @$_POST['pitem_id'];


    if (($msg = $obj->store())) {
        $AppUI->setMsg( $msg, UI_MSG_ERROR );
    } else {
        $AppUI->setMsg( $isNotNew ? 'Reference line updated' : 'Reference line added', UI_MSG_OK, true );
    }
    $AppUI->redirect();
}
?>
